package com.example.camerafw;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;

import com.framework.camera.MyAsyncTask;
import com.framework.camera.NetworkControl;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity implements OnClickListener{

	Button startButton = null;
    private Socket socket;
	private static final int SERVERPORT = 15680;
	private static final String SERVER_IP = "172.16.1.28";
	NetworkControl netctrl;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		startButton = (Button)findViewById(R.id.button1);
		
		startButton.setOnClickListener(this);
    
//		new Thread(new ClientThread()).start();
		
	}
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		// TODO 自動生成されたメソッド・スタブ

	      new MyAsyncTask(this).execute("Param1", "Param2");
    

//
//        try {
//	            EditText et = (EditText) findViewById(R.id.editText1);
//	            String str = et.getText().toString();
//	            PrintWriter out = new PrintWriter(new BufferedWriter(
//	                    new OutputStreamWriter(socket.getOutputStream())),
//	                    true);
//	            out.println(str);
//	        } catch (UnknownHostException e) {
//	            e.printStackTrace();
//	        } catch (IOException e) {
//	            e.printStackTrace();
//	        } catch (Exception e) {
//	            e.printStackTrace();
//	        }
//        

	}

    class ClientThread implements Runnable {	 
	        @Override
	        public void run() {
	 
	            try {
	                InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
	 
	                socket = new Socket(serverAddr, SERVERPORT);
	 
	            } catch (UnknownHostException e1) {
	                e1.printStackTrace();
	            } catch (IOException e1) {
	                e1.printStackTrace();
	            }
	 
	        }
	 
	    }
}
